package com.xique.door.project.miniprogram.controller;

import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.project.miniprogram.bean.domian.Car;
import com.xique.door.project.miniprogram.service.IMiniCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mine/car")
public class MiniCarController {

  @Autowired private IMiniCarService miniCarService;


  @PostMapping("/addCar")
  public AjaxResult insertMiniCar(@RequestBody Car car) {
    Long userId = SecurityUtils.getUserId();
    Long  baseUserId= SecurityUtils.getBaseUserId();
    car.setUserId(userId);
    car.setBaseId(baseUserId);
   return miniCarService.insertMiniCar(car);

  }

  @PutMapping("/updateeCar")
  public AjaxResult updateeCar(@RequestBody Car car) {
    return miniCarService.updateeCar(car.getId(),car.getLicensePlate());
  }

  @GetMapping("/deleteCar")
  public AjaxResult getdeleteCar(Long id) {
    return miniCarService.getdeleteCar(id);
  }

  @GetMapping("/getList")
  public AjaxResult getCarList( Integer pageNum, Integer pageSize) {
    Long userId = SecurityUtils.getUserId();
    return AjaxResult.success(miniCarService.getCarList(userId,pageNum,pageSize)) ;
  }

}
